package com.zj.juc.study.interrupted;

import java.util.concurrent.TimeUnit;

/**
 * @author 自己的名字
 * @version 1.0.0
 * @ClassName InterruptedDemo
 * @Description interrupte
 * @createTime 2024年12月26日 20:57
 */
public class InterruptedVolatileDemo
{
    static volatile boolean isStop = false;

    public static void main(String[] args) {
        new Thread(()->{
            while (true){
                if (isStop){
                    System.out.println(Thread.currentThread().getName()+"modify volatile is true");
                    break;
                }
                System.out.println("hello volatile");
            }
        },"t1").start();
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(()->{
            isStop = true;
        },"t2").start();
    }
}
